<?php
/**
 * Created by PhpStorm.
 * User: 快定
 * Date: 2021/7/7
 * Time: 16:30
 */

class User extends AppModel
{
    /*
     * 查询user表总数
     */
    public function count()
    {
        $this->setSource('users');
        $count = $this->find('count');
        return $count;
    }

    public function getCity($uid)
    {
       $res = $this->query("select * from citys where pid = {$uid}");
       return $res;
    }

    /*
     * 分页查询
     */
    public function findUser($page, $limit)
    {
        $this->setSource('users');
        $data = $this->find('all', array(
            'fields' => ['id','username','province','city','district','location','phone','nickname','email','sign','create_time'],
            'limit' => $limit,
            'page' => $page,
        ));
        return $data;
    }

    //我的背包
    public function rucksack($uid)
    {
        $this->setSource("rucksack");
        $res = $this->find('all', [
            'fields' => ['uid', 'prid', 'num','u.nickname','p.prop_name'],
            'joins' => [
                [
                    'table' => 'users',
                    'alias' => 'u',
                    'type' => 'left',
                    'conditions' => ['u.id = User.uid'],
                ],
                [
                    'table' => 'prop',
                    'alias' => 'p',
                    'type' => 'left',
                    'conditions' => ['p.id = User.prid'],
                ],
            ],
            'conditions' => ['uid' => $uid],
        ]);
        return $res;
    }

    public function dellAddress($data)
    {
        $this->setSource('users');
        return $this->save($data);
    }
}